// ==UserScript==
// @name         gitlab代码审查工具
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  gitlab代码审查工具!
// @author       zxy
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/1.12.4/jquery.min.js
// @include      *//git.youlu.com/FE/tool/tool_review-code-vehicle/issues/*
// ==/UserScript==

(function () {
  'use strict';

  // Your code here...

  setTimeout(() => {
    $('.note-body.js-task-list-container.is-task-list-enabled').each(function () {
      // 隐藏已评分区块
      const tds = $('table[dir="auto"] tbody td', $(this));
      let hasNull = false;
      tds.each(function () {
        if (!$(this).html()) {
          hasNull = true;
        }
      });
      if (!hasNull) {
        $(this).hide();
      }
      // 隐藏合并分支的区块
      const merges = $('ul[dir="auto"] li', $(this));
      merges.each(function () {
        if (/Merge branch/.test($(this).html())) {
          $(this).hide();
        }
      });
      // 给区块加上展开收起按钮
      const showBtn = $(`<div style="position: absolute;left: 50%;
      top: 0;color: red;cursor: pointer;">${hasNull ? '点击收起' : '点击展开'}</div>`);
      showBtn.click(function () {
        $(this).siblings('.js-task-list-container').toggle();
        $(this).html($(this).html() === '点击展开' ? '点击收起' : '点击展开');
      });
      $(this).parent().css('position', 'relative').append(showBtn);
    });
  }, 1500);
})();
